package com.victor.zjbj_android.mod.zhongxin;

import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.TextView;

import com.blankj.utilcode.util.ActivityUtils;
import com.blankj.utilcode.util.LogUtils;
import com.blankj.utilcode.util.ToastUtils;
import com.victor.zjbj_android.R;
import com.victor.zjbj_android.base.BaseActivity;
import com.victor.zjbj_android.bean.LoginConfig;
import com.victor.zjbj_android.mod.login.LoginActivity;
import com.victor.zjbj_android.MainActivity;
import com.victor.zjbj_android.utils.LoginUtils;
import com.victor.zjbj_android.utils.MainUtils;


/**
 * Created by liuwei on 2018/4/19 2018/4/21.
 */

public class CenterActivity extends BaseActivity {

    private TextView tv_name,tv_zhanghao,tv_role,tv_zubie,tv_num;
    @Override
    protected int getResourcesId() {
        return R.layout.activity_center;
    }

    @Override
    protected void init(Bundle savedInstanceState) {
        tv_name=findViewById(R.id.tv_name);
        tv_zhanghao=findViewById(R.id.tv_zhanghao);
        tv_role=findViewById(R.id.tv_role);
        tv_zubie=findViewById(R.id.tv_zubie);
        tv_num=findViewById(R.id.tv_num);
        findViewById(R.id.ll_xiugaimima).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                startActivity(new Intent(CenterActivity.this,XiugaiMimaActivity.class));
            }
        });
        findViewById(R.id.iv_back).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
        findViewById(R.id.ll_exit).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                LoginConfig.setLoginConfig(LoginConfig.getInstance().setAutoLogin(false).setuid("")
                        .setAppToken("")
                        .setUsername("")

                );

                ToastUtils.showShort("已退出登录!");
                try {
                    LoginUtils.setLoginConfig(CenterActivity.this, LoginUtils.serialize(LoginConfig.getLoginConfig()));
                } catch (Exception e) {
                    Log.e("e", e.getMessage());
                }
                startActivity(new Intent(CenterActivity.this,LoginActivity.class));
                ActivityUtils.finishAllActivities();
            }
        });
        if(MainUtils.isOnline(CenterActivity.this)){
            tv_name.setText(LoginUtils.getLoginConfig(this).getUsername());
            tv_zhanghao.setText(LoginUtils.getLoginConfig(this).getuid());
            tv_role.setText(LoginUtils.getLoginConfig(this).getRole());
        }
    }

}
